//=============================================================================
// Modified MP7 MedicGun Inventory class
//=============================================================================
class M7A3MW extends SRKFWeapon;

#exec OBJ LOAD FILE="..\Textures\KFWeaponPackTex.utx"

var ()      float       AmmoRegenRate2;  // How quickly the healing charge regenerates
var ()      int         HealBoostAmount2;// How much we heal a player by default with the heal dart
const MaxAmmoCount=500;                 // Maximum healing charge count
var         float       RegenTimer;     // Tracks regeneration
var         int         HealAmmoCharge2; // Current healing charger
var localized   string  SuccessfulHealMessage2;
var() Material ScopeGreen;
var() Material ScopeRed;
var() ScriptedTexture MyScriptedTexture;
var() Shader AmmoCounter;
var string MyMessage;
var int MyHealth;
var   Font MyFont;
var   Font MyFont2;
var   Font SmallMyFont;
var  color MyFontColor;
var  color MyFontColor2;
var int OldValue;

replication
{
	// Things the server should send to the client.
	reliable if( Role==ROLE_Authority )
		HealAmmoCharge2;

	reliable if( Role == ROLE_Authority )
		ClientSuccessfulHeal2;
}

// The server lets the client know they successfully healed someone
simulated function ClientSuccessfulHeal2(String HealedName)
{
	if( PlayerController(Instigator.Controller) != none )
	{
		PlayerController(Instigator.controller).ClientMessage(SuccessfulHealMessage2@HealedName, 'CriticalEvent');
	}
}

// Return a float value representing the current healing charge amount
simulated function float ChargeBar()
{
	return FClamp(float(HealAmmoCharge2)/float(MaxAmmoCount),0,1);
}

simulated function MaxOutAmmo()
{
	if ( bNoAmmoInstances )
	{
		if ( AmmoClass[0] != None )
			AmmoCharge[0] = MaxAmmo(0);
		return;
	}
	if ( Ammo[0] != None )
		Ammo[0].AmmoAmount = Ammo[0].MaxAmmo;

	HealAmmoCharge2 = MaxAmmoCount;
}

simulated function SuperMaxOutAmmo()
{
HealAmmoCharge2 = 999;

	if ( bNoAmmoInstances )
	{
		if ( AmmoClass[0] != None )
			AmmoCharge[0] = 999;
		return;
	}
	if ( Ammo[0] != None )
		Ammo[0].AmmoAmount = 999;
}

simulated function int MaxAmmo(int mode)
{
	if( Mode == 1 )
	{
	return MaxAmmoCount;
	}
	else
	{
	return Super.MaxAmmo(mode);
	}
}

simulated function FillToInitialAmmo()
{
	if ( bNoAmmoInstances )
	{
		if ( AmmoClass[0] != None )
			AmmoCharge[0] = Max(AmmoCharge[0], AmmoClass[0].Default.InitialAmount);
		HealAmmoCharge2 = MaxAmmoCount;

		return;
	}

	if ( Ammo[0] != None )
		Ammo[0].AmmoAmount = Ammo[0].AmmoAmount;

	HealAmmoCharge2 = MaxAmmoCount;

}

simulated function int AmmoAmount(int mode)
{
	if( Mode == 1 )
	{
	return HealAmmoCharge2;
	MyHealth = ChargeBar() * 100;
	}
	else
	{
	return Super.AmmoAmount(mode);
	}
}

simulated function bool AmmoMaxed(int mode)
{
	if( Mode == 1 )
	{
	return HealAmmoCharge2>=MaxAmmoCount;
	}
	else
	{
	return Super.AmmoMaxed(mode);
	}
}

simulated function float AmmoStatus(optional int Mode) // returns float value for ammo amount
{
	if( Mode == 1 )
	{
	return float(HealAmmoCharge2)/float(MaxAmmoCount);
	}
	else
	{
	return Super.AmmoStatus(Mode);
	}
}

simulated function bool ConsumeAmmo(int Mode, float load, optional bool bAmountNeededIsMax)
{
	if( Mode == 1 )
	{
		if( Load>HealAmmoCharge2 )
		{
			return false;
		}

		HealAmmoCharge2-=Load;
		Return True;
	}
	else
	{
	return Super.ConsumeAmmo(Mode, load, bAmountNeededIsMax);
	}
}

function bool AddAmmo(int AmmoToAdd, int Mode)
{
	if( Mode == 1 )
	{
		if( HealAmmoCharge2<MaxAmmoCount )
		{

			HealAmmoCharge2+=AmmoToAdd;
			if( HealAmmoCharge2>MaxAmmoCount )
			{
				HealAmmoCharge2 = MaxAmmoCount;
			}
		}
		return true;
	}
	else
	{
		return Super.AddAmmo(AmmoToAdd,Mode);
	}
}

simulated function bool HasAmmo()
{
	if( HealAmmoCharge2 > 0 )
	{
		return true;
	}

	if ( bNoAmmoInstances )
	{
		return ( (AmmoClass[0] != none && FireMode[0] != none && AmmoCharge[0] >= FireMode[0].AmmoPerFire) );
	}
	return (Ammo[0] != none && FireMode[0] != none && Ammo[0].AmmoAmount >= FireMode[0].AmmoPerFire);
}

simulated function CheckOutOfAmmo()
{
	return;
}

simulated function Tick(float dt)
{ 
	if ( Level.NetMode!=NM_Client && HealAmmoCharge2<MaxAmmoCount && RegenTimer<Level.TimeSeconds )
	{

		RegenTimer = Level.TimeSeconds + AmmoRegenRate2;

		if ( KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo) != none && KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo).ClientVeteranSkill != none )
		{

			HealAmmoCharge2 += 10 * KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo).ClientVeteranSkill.Static.GetSyringeChargeRate(KFPlayerReplicationInfo(Instigator.PlayerReplicationInfo));

		}
		else
		{

			HealAmmoCharge2 += 10;
		}
		if ( HealAmmoCharge2 > MaxAmmoCount )
		{

			HealAmmoCharge2 = MaxAmmoCount;
		}
	}



}

simulated function bool StartFire(int Mode)
{

	if( Mode == 1 )
		return Super.StartFire(Mode);


	if( !Super.StartFire(Mode) )  // returns false when mag is empty
	return false;

	if( AmmoAmount(0) <= 0 )
	{

		return false;
	}

	AnimStopLooping();

	if( !FireMode[Mode].IsInState('FireLoop') && (AmmoAmount(0) > 0) )
	{

		FireMode[Mode].StartFiring();


		return true;
	}
	else
	{
		return false;
	}

	return true;


}



simulated function AnimEnd(int channel)
{
	local name anim;
	local float frame, rate;

	if(!FireMode[0].IsInState('FireLoop'))
	{
		GetAnimParams(0, anim, frame, rate);

		if (ClientState == WS_ReadyToFire)
		{
			if ((FireMode[0] == None || !FireMode[0].bIsFiring) && (FireMode[1] == None || !FireMode[1].bIsFiring))
			{
				PlayIdle();
			}
		}
	}
}

simulated function bool CanZoomNow()
{
	Return (!FireMode[0].bIsFiring && Instigator!=None && Instigator.Physics!=PHYS_Falling);
}





simulated final function SetTextColor( byte R, byte G, byte B )
{
	MyFontColor.R = R;
	MyFontColor.G = G;
	MyFontColor.B = B;
	MyFontColor.A = 255;


}

simulated final function SetTextColor2( byte R, byte G, byte B )
{
	MyFontColor2.R = R;
	MyFontColor2.G = G;
	MyFontColor2.B = B;
	MyFontColor2.A = 255;

}

simulated function RenderOverlays( Canvas Canvas )
{

if( HealAmmoCharge2 >=250 )
	{

	MyHealth = ChargeBar() * 100;
	SetTextColor2(76,148,177);
	++MyScriptedTexture.Revision;
	}
	else
	{
	MyHealth = ChargeBar() * 100;
	SetTextColor2(218,18,18);
	++MyScriptedTexture.Revision;
	}
	if( AmmoAmount(0) <= 0 )
	{
		if( OldValue!=-5 )
		{
			OldValue = -5;
			Skins[5] = ScopeRed;
			MyFont = SmallMyFont;
			SetTextColor(218,18,18);
			MyMessage = "Empty";
			++MyScriptedTexture.Revision;
		}
	}
	else if( bIsReloading )
	{
		if( OldValue!=-4 )
		{
			OldValue = -4;
			MyFont = SmallMyFont;
			SetTextColor(32,187,112);
			MyMessage = "REL";
			++MyScriptedTexture.Revision;
		}
	}
	else if( OldValue!=(MagAmmoRemaining+1) )
	{
		OldValue = MagAmmoRemaining+1;
		Skins[5] = ScopeGreen;
		MyFont = Default.MyFont;

		if ((MagAmmoRemaining ) <= (MagCapacity/2))
			SetTextColor(32,187,112);
		if ((MagAmmoRemaining ) <= (MagCapacity/3))
		{
			SetTextColor(218,18,18);
			Skins[5] = ScopeRed;
		}
		if ((MagAmmoRemaining ) >= (MagCapacity/2))
			SetTextColor(76,148,177);
		MyMessage = String(MagAmmoRemaining);

		++MyScriptedTexture.Revision;
	}

	MyScriptedTexture.Client = Self;
	//Skins[5] = AmmoCounter;
	Super.RenderOverlays(Canvas);
	MyScriptedTexture.Client = None;
	//Skins[5] = None;
}
simulated function RenderTexture( ScriptedTexture Tex )
{
	local int w, h;

	// Ammo
	Tex.TextSize( MyMessage, MyFont, w, h );
	Tex.DrawText( ( Tex.USize / 2 ) - ( w / 2 ), ( Tex.VSize / 2 ) - ( h / 1.2 ),MyMessage, MyFont, MyFontColor );
	// Health
	Tex.TextSize( MyHealth, MyFont2, w, h );
	Tex.DrawText( ( Tex.USize / 2 ) - ( w / 2 ), ( Tex.VSize / 2 ) - 8 ,MyHealth, MyFont2, MyFontColor2 );
}

defaultproperties
{
     AmmoRegenRate2=0.300000
     HealBoostAmount2=20
     HealAmmoCharge2=500
     SuccessfulHealMessage2="You healed "
     ScopeGreen=Shader'KFWeaponPackTex.M7A3.Scope_Finall'
     ScopeRed=Shader'KFWeaponPackTex.M7A3.ScopeRed_Shader'
     MyScriptedTexture=ScriptedTexture'KFWeaponPackTex.M7A3_Ammo_Script.AmmoNumber'
     MyFont=Font'IJCFonts.DigitalBig'
     MyFont2=Font'IJCFonts.DigitalBig'
     SmallMyFont=Font'IJCFonts.DigitalMed'
     MyFontColor=(B=177,G=148,R=76,A=255)
     MyFontColor2=(B=177,G=148,R=76,A=255)
     MagCapacity=30
     ReloadRate=3.066000
     ReloadAnim="Reload"
     ReloadAnimRate=1.000000
     WeaponReloadAnim="Reload"
     HudImage=Texture'KFWeaponPackTex.Icon.M7A3_idle'
     SelectedHudImage=Texture'KFWeaponPackTex.Icon.M7A3_inuse'
     Weight=4.000000
     bHasAimingMode=True
     IdleAimAnim="Idle_Iron"
     StandardDisplayFOV=55.000000
     bModeZeroCanDryFire=True
     SleeveNum=0
     TraderInfoTexture=Texture'KFWeaponPackTex.Icon.M7A3_Trader'
     PlayerIronSightFOV=65.000000
     ZoomedDisplayFOV=45.000000
     FireModeClass(0)=Class'PerksSimHostOrg.M7A3MWFire'
     FireModeClass(1)=Class'PerksSimHostOrg.M7A3MWFireB'
     PutDownAnim="PutDown"
     SelectSound=Sound'KF_MP7Snd.MP7_Select'
     SelectForce="SwitchToAssaultRifle"
     AIRating=0.550000
     CurrentRating=0.550000
     bShowChargingBar=True
     Description="An advanced prototype assault rifle. Modified to fire healing darts."
     EffectOffset=(X=100.000000,Y=25.000000,Z=-10.000000)
     DisplayFOV=55.000000
     Priority=11
     InventoryGroup=4
     GroupOffset=8
     PickupClass=Class'PerksSimHostOrg.M7A3MWPickup'
     PlayerViewOffset=(X=9.500000,Y=9.000000,Z=-1.200000)
     BobDamping=5.500000
     AttachmentClass=Class'PerksSimHostOrg.M7A3MWAttachment'
     IconCoords=(X1=245,Y1=39,X2=329,Y2=79)
     ItemName="M7A3 Medic Gun"
     Mesh=SkeletalMesh'KFWeaponPackAnims.M7A3'
     Skins(3)=Combiner'KF_Weapons2_Trip_T.Special.MP_7_cmb'
     TransientSoundVolume=1.250000
}
